package com.aivin.firplugin.dialog;

import com.aivin.firplugin.tool.ResourceTool;
import com.aivin.firplugin.view.ApkInfoPanel;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.ui.DialogWrapper;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;


public class ApkInfoInputDialog extends DialogWrapper {
    private ApkInfoPanel apkInfoInput;

    public ApkInfoInputDialog(@Nullable Project project) {
        super(project);
        this.setResizable(true);
        apkInfoInput = new ApkInfoPanel( );
        setOKButtonText(ResourceTool.instance().getString("nextStep") );
        setCancelButtonText(ResourceTool.instance().getString("cancel"));
        setResizable(false); // 禁止拖动改变大小
        init();
    }



    @Nullable
    @Override
    protected JComponent createCenterPanel() {
        return apkInfoInput.getApkInfoPanel();
    }

    @Override
    public void doOKAction() {
//        super.doOKAction();

        boolean isRead =apkInfoInput.isApkReady() ;
        if(!isRead){
            return;
        }

        String updateLog=apkInfoInput.getUpdateLog();
        final Project project = ProjectManager.getInstance().getDefaultProject();
        String api_token =apkInfoInput.getApiTokenStr();
        String bundleID =apkInfoInput.getSelectedApp().getBundle_id();
        ApkUploadDialog apkUploadDialog =
                new ApkUploadDialog(project ,apkInfoInput.getApkPath()  ,bundleID ,api_token,updateLog);
        apkUploadDialog.setTitle(ResourceTool.instance().getString("upLoadTitle"));
        apkUploadDialog.show();
    }

}
